package singleton;

/**
 * @ClassName : lazy
 * @Description : 懒汉式-双重锁方式
 * @Author : gyh
 * @Date: 2021-09-04 17:39
 */
public class lazy {
    private static lazy instance;

    private lazy() {
    }

    public static lazy getInstance() {
        if (instance == null) {
            synchronized (lazy.class) {
                if (instance == null) {
                    instance = new lazy();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                System.out.println(lazy.getInstance().hashCode());
            }).start();
        }
    }
}
